<!DOCTYPE html>
<html lang="zh" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>宝钢工程</title>
    <link href="../static/css/todostyle.css" rel="stylesheet" th:href="@{/css/todostyle.css}"/>
    <link rel="stylesheet" th:href="@{/css/bootstrap.min.css}"/>
    <link rel="stylesheet" th:href="@{/css/font-awesome.min.css}"/>
    <!-- bootstrap-table 表格插件样式 -->
    <link rel="stylesheet" th:href="@{/ajax/libs/bootstrap-table/bootstrap-table.min.css}"/>
    <link rel="stylesheet" th:href="@{/ajax/libs/bootstrap-treetable/bootstrap-treetable.css}"/>
    <link rel="stylesheet"
          th:href="@{/ajax/libs/bootstrap-table/extensions/columns/bootstrap-table-fixed-columns.css}"/>
    <link rel="stylesheet" th:href="@{/css/animate.css}"/>
    <link rel="stylesheet" th:href="@{/css/style.css}"/>
    <link rel="stylesheet" th:href="@{/ajax/libs/select/select2.css}"/>
    <link rel="stylesheet" th:href="@{/ruoyi/css/ry-ui.css}"/>
</head>
<style>
    #table tbody tr:nth-child(even) {
        background: #E1F9FF;
    }

    .import {
        margin: 10px 50px 0 0 ! important;
    }

    #table th {
        width: 100px;
    }

    #table td {
        overflow: hidden;
        white-space: nowrap;
        text-overflow: ellipsis;
        font-size: 15px
    }


    /* #table td:hover ~ td{overflow: visible;  white-space: normal;}
    #table td:hover{overflow: visible;   white-space: normal;} */
</style>
<body>
<div class="Top_bseg"><!--<img src="/img/todologo.png"/><h3></h3>--></div>
<!-- <div class="col-sm-12">
        <ul class="nav nav-pills nav-justified step step-arrow jdt">
            <li th:each="approver:${approverList}" th:class="${approver.approverStatus!='0'}?'dwc':'' "><a th:text="${approver.approverStatus!='0'}? ${approver.approverCode}+'（待评价）':${approver.approverCode}+'（已评价）' "></a></li>
        </ul>
    </div> -->
<div class="evaluate">
    <div class="evaluate_a row ">
        <input id="notTitle" th:value="${pefassproject.noticeTitle}" type="hidden"/>
        <input id="notValue" th:value="${pefassproject.noticeValue}" type="hidden"/>
        <input id="apportionDataBackResion" th:value="${apportionDataBackResion}" type="hidden"/>
        <input id="peftempletindicatorID" name="peftempletindicatorID" type="hidden"><!-- 待办人员角色 -->
        <input id="treeId" name="memberCode" type="hidden">
        <input id="projectId" name="projectId" th:value="${pefassproject.id}" type="hidden">
        <input id="typeYB" th:value="${type}" type="hidden"/>
        <input id="deptId" th:value="${deptId}" type="hidden"/>
        <div aria-hidden="true" class="modal inmodal fade" id="tips_b"
             role="dialog" style="display: none;" tabindex="-1">
            <div class="modal-dialog modal-lg">
                <div class="modal-content">
                    <div class="modal-header">
                        <h3 th:text="${pefassproject.noticeTitle}"></h3>
                    </div>
                    <div class="modal-body">
                        <p id="noticeValue" style="white-space:pre-line;padding: 17px 35px;"></p>
                    </div>
                    <div class="modal-footer">
                        <button class="btn btn-white" data-dismiss="modal" type="button">好的，知道了</button>
                    </div>
                </div>
            </div>
        </div>
        <div class="col-sm-6">
            <div class="tou tou2">
                <i class="glyphicon glyphicon-list-alt" id="hei_mg"></i>&nbsp;&nbsp;&nbsp;&nbsp;<h2
                    th:text="${pefassproject.projectName}"></h2>
                &nbsp;&nbsp;&nbsp;&nbsp;
                <i class="fa fa-clock-o"></i>&nbsp;&nbsp;<span
                    th:text="${#dates.format(pefassproject.assessTimeFrom, 'yyyy-MM-dd')}"></span>····<span
                    th:text="${#dates.format(pefassproject.assessTimeTo, 'yyyy-MM-dd')}"></span>
                <div class="sy" th:if="${days>=0}">剩余<span th:text="${days}"></span>天</div>
                <div class="sy" th:if="${days<0}"><span>已过期</span></div>
            </div>
            <br>
            <div class="tou2">
            </div>
        </div>

        <ul class="ul1">
            <li><span class="spans">考核对象：</span><span th:text="${pefctasstable.memberName}"></span></li>
            <li><span class="spans">绩效模板：</span><span th:text="${pefassproject.projectName}"></span></li>
        </ul>
        <ul class="ul2_mg">
            <li><span class="spans">展现形式：</span><span th:text="${pefassproject.showtype}"></span></li>
            <li><span class="spans">考核周期：</span><span
                    th:text="${@dict.getLabel('zzjx_pefindicator_checkcyc', pefassproject.cycleValue)}"></span></li>
        </ul>
        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="importExcel()" th:if="${type!=1}"><i
                    class="glyphicon glyphicon-save"></i>导入</a>
            <!-- 此按钮导出方法暂时只支持IE和Chrome -->
            <a class="btn btn-success" onclick="exportData()"><i class="glyphicon glyphicon-open"></i>导出</a>
            <a onclick="selectDept()"
               th:class="${type==1}?'btn btn-success disabled':'btn btn-success'" th:if="${pefassproject.projectStatus!='6'}"><i class="fa fa-plus"></i>分解 </a>
            <a onclick="insertRow()"
               th:class="${type==1}?'btn btn-success disabled':'btn btn-success'" th:if="${pefassproject.projectStatus!='6'}"> <i class="fa fa-plus"></i>新增指标</a>
            <a onclick="myApportion()"
               th:class="${type!=1}?'btn btn-success disabled':'btn btn-success'" th:if="${pefassproject.projectStatus!='6'}"><i class="fa fa-plus"></i>已分解列表 </a>
        </div>
        <div class="backResion1">
            <div class="backResion">
                <p id="backResion"></p>
            </div>
        </div>

    </div>
    <!-- <div class="evaluate_b_but">
        <button>保存</button><button>提交</button>
    </div> -->
    <form class="form-horizontal m" id="form-kaoping">
        <input id="id" name="id" th:value="${approver.id}" type="hidden">
        <input id="roleId" name="roleId" th:value="${roleId}" type="hidden"><!-- 待办人员角色 -->
        <input id="tableId" name="tableId" th:value="${approver.tableId}" type="hidden">
        <input id="approveorder" name="approveorder" th:value="${approver.approveorder}" type="hidden">
    </form>

    <div class="evaluate_c table2excel" id="tableDiv" style="width: 98%;padding-left:2%;">
        <div id="xq">
            鼠标悬浮显示详情框
        </div>
        <form id="formTable">
            <table data-mobile-responsive="true" id="table">
                <!-- 在此处填充表格数据 -->
            </table>
        </form>
        <!-- 此表格只为导出数据 -->
        <table data-mobile-responsive="true" id="table2" style="display: none">
            <!-- 在此处填充表格数据 -->
        </table>
    </div>
    <div class="evaluate_b_but" style="margin: 20px 0 50px 0;text-align: center;">
        <div style="float: left;width:30%;">
            <button onclick="loadFiles('A')"
                    th:style="${deptparamRole.isCheck=='Y'}?'display:inline;width:auto;':'display:none;width:auto;'" th:text="${pefassobject.myRemark!=null}?'查看'+${pefassobject.myRemark}:'查看附件'"
                    type="button"><i
                    class="fa fa-search"></i></button>
            <button onclick="loadFiles('B')"
                    th:style="${deptparamRole.isCheck=='Y'}?'display:inline;width:auto;':'display:none;width:auto;'" th:text="${pefassobject.otherRemark!=null}?'查看'+${pefassobject.otherRemark}:'查看附件'"
                    type="button"><i
                    class="fa fa-search"></i></button>
            <button onclick="uploadFiles('B')"
                    th:style="${deptparamRole.isUpload=='Y'}?'display:inline;width:auto;':'display:none;width:auto;'" th:text="${pefassobject.otherRemark!=null}?'上传'+${pefassobject.otherRemark}:'上传附件'"
                    type="button"><i
                    class="fa fa-upload"></i></button>
            <input id="isUpload" th:value="${deptparamRole.isUpload}" type="hidden"/>
        </div>
        <button onclick="doSubmit('BC')" th:if="${type!=1}">保存</button>
        <button onclick="doSubmit('TJ')" th:if="${type!=1}">提交</button>
        <!-- <button th:if="${type!=1}" type="button" data-toggle="modal" data-target="#myModal" id="btn-reason">
            退回
        </button>
        <button th:if="${type==1}" onclick="appealfun()">申诉</button>
        <button onclick="closeItem()">取消</button>
        -->
        <!-- Button trigger modal -->

        <!--<button onclick="getDate()">得到数据</button>
        <button onclick="getTableTh()">得到表头数据</button>-->
    </div>
    <!--modal-->
    <div aria-labelledby="myModalLabel" class="modal fade" id="myModal" role="dialog" tabindex="-1">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button aria-label="Close" class="close" data-dismiss="modal" type="button"><span
                            aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title" id="myModalLabel">退回原因</h4>
                </div>
                <div class="modal-body">
                    <form class="form-horizontal" id="frm-reason">
                        <textarea class="form-control" id="remark" name="remark" rows="3"></textarea>
                    </form>
                </div>
                <div class="modal-footer">
                    <button class="btn btn-default" data-dismiss="modal" type="button">关闭</button>
                    <button class="btn btn-primary" onclick="doReason()" type="button">提交</button>
                </div>
            </div>
        </div>
    </div>
</div>

<div th:include="include :: footer"></div>
<style>
    .backResion1 {
        padding: 0 20px;
        float: right;
    }

    .backResion p {
        font-size: 15px;
        color: orange;
    }
</style>

<script th:src="@{/ajax/libs/bootstrap-table/extensions/export/export.js}"></script>
<script th:src="@{/ajax/libs/bootstrap-table/extensions/export/xlsx.full.min.js}"></script>
<script th:src="@{/ajax/libs/table2excel/jquery.table2excel.js}"></script>
<script charset="UTF-8" th:src="@{/js/rule.js}" type="text/javascript"></script>
<!-- jquery-validate 表单验证插件 -->
<script th:src="@{/ajax/libs/validate/jquery.validate.min.js}"></script>
<script th:src="@{/ajax/libs/validate/messages_zh.min.js}"></script>
<script th:src="@{/ajax/libs/validate/jquery.validate.extend.js}"></script>
<script th:inline="javascript">
    var prefix = ctx + "zzjx/pefctasstable";
    var data = [];
    var beforeAddRowLen = 0;
    var affterAddRowLen = 0;
    $(function () {
        var tipsTitle = $("#notTitle").val();
        var tipsValue = $("#notValue").val();
        var apportionDataBackResion = $("#apportionDataBackResion").val();
        if (tipsTitle != "" && tipsTitle != null && tipsValue != "" && tipsValue != null) {
            $("#noticeValue").html(tipsValue.replace(/<br>/g, ""));
            $("#tips_b").modal("show");
            setTimeout(function () {
                $("#tips_b").modal("hide");
            }, 15000);
        }
        //是否是退回考核内容，如果是，显示退回原因
        if (apportionDataBackResion != "" && apportionDataBackResion != null) {
            $("#backResion").html("退回原因：" + apportionDataBackResion)
        }
        doChange(); //初始化表格信息
        $.modal.closeLoading();
        //校验是否可以退回
        var approveorder = $("#approveorder").val();
        if (approveorder == "1") {
            $("#btn-reason").hide();
        } else {
            $("#btn-reason").show();
        }
        loadMsg();
    })

    function bding() {
        $("td").mouseover(function (e) {
            var a = $(this).html();
            if (a.indexOf("<input") != -1 || a.indexOf("<select") != -1 || a.indexOf("<textarea") != -1 || a.length < 7) {
                return;
            }
            $("#xq").html(a);
            $("#xq").css({"position": "absolute", "top": e.pageY + 15, "left": e.pageX - 75}).show();
        });
        $("td").mousemove(function (e) {
            $("#xq").css({
                "position": "absolute",
                "opacity": "0.7",
                "background-color": "666",
                "top": e.pageY + 15,
                "left": e.pageX - 75
            });
        });
        $("td").mouseout(function () {
            $("#xq").hide();
        });
    }

    /**
     * 提交按钮
     * @param submitType 提交类型，是保存还是提交 TJ：提交 BC：保存
     */
    function doSubmit(submitType) {
        var data = $("#form-kaoping").serializeArray();
        data.push({"name": "submitType", "value": submitType});
        debugger;

        var rows = $("#table").bootstrapTable('getData');
        var tableDataJson = null;
        var affterAddRowLen = $("#table").bootstrapTable('getData').length;
        var rowList = new Array();

        if (affterAddRowLen > beforeAddRowLen) {
            for (var i = beforeAddRowLen; i < affterAddRowLen; i++) {

                rows.splice(i, 1)

            }

        }

        data.push({"name": "tableDataJson", "value": JSON.stringify(rows)});
        if (submitType == "TJ") {
            if (!$.rule.checkTableRequired()) {
                $.modal.alertError("请将信息填写完整后提交!");
                return;
            }
        }
        $.operate.saveTab(ctx + "zzjx/approver/doSubmit", data);
    }

    /**
     *    退回原因
     */
    function doReason() {
        var remark = $("#remark").val();
        var tableId = $("#tableId").val(); //表单id
        var approveorder = $("#approveorder").val();
        $.ajax({
            url: ctx + "zzjx/approveResult/save/" + $("#id").val(),
            data: {"remark": remark, "tableId": tableId, "approveorder": approveorder},
            dataType: "json",
            type: "POST",
            async: false,
            success: function (result) {
                $.modal.alertSuccess(result.msg);
                $('#myModal').modal('hide');
            },
            error: function () {
                $.modal.alertError("提交失败!");
            }
        })
    }


    var formulaMap = null; //公式
    var dictData = null;	//表头 rule.js需要用到这两个，一定要声明为全局变量
    /**
     * 更改模板，重新加载预览信息
     * @returns {boolean}
     */
    function doChange() {
        var id = $("#id").val();
        var tableId = $("#tableId").val(); //表单id
        if (tableId != "") {
            $.modal.loading("请等待加载预览信息!");
            $.ajax({
                url: ctx + "zzjx/pefctasstable/preview"
                , data: {"tableId": tableId, "id": id, "time": (new Date()).getTime()}
                , dataType: "JSON"
                , type: "GET"
                , async: false
                , success: function (result) {
                    $.table.destroy("table");
                    dictData = result.dictData;

                    formulaMap = result.formulaMap;
                    var list = result.list;
                    buildTable($('#table'), dictData.length, list.length, dictData, list);
                    data = dictData;
                    //构建第二个table只为导出数据使用
                    buildTable2($('#table2'), dictData.length, list.length, dictData, list);
                    $.modal.closeLoading();
                }, error: function () {
                    $.modal.closeLoading();
                    $.modal.alertError("获取预览信息失败!");
                }
            })
            $("#tableDiv").removeClass("hidden");
            return false;
        }
        $("#tableDiv").addClass("hidden");
    }


    /**
     * 构建预览信息表格
     * @param $el
     * @param cells
     * @param rows
     * @param dictData
     * @param list
     */
    function buildTable($el, cells, rows, dictData, list) {
        var roleId = $("#roleId").val();

        var i, j, row, columns = [], data = [];
        var isDisabled = false;
        if ($("#typeYB").val() == 1) {
            isDisabled = true;
        }

        columns.push({
            checkbox: true
        })

        columns.push({
            field: "id",
            title: "ID",
            visible: false
        })
        //拼接table,拼接表头
        for (var dd in dictData) {
            var dictLabel = dictData[dd]["dictLabel"];//显示名称
            var dictValue = dictData[dd]["dictValue"];//字段值
            var listClass = dictData[dd]["listClass"];//列显示类型(输入框，下拉框，显示)
            var isMustFill = dictData[dd]["isMustFill"];//是否为空
            var fillRoleIds = dictData[dd]["fillRoleIds"];//可评角色ID
            var f = {
                field: dictValue,
                title: dictLabel,
                sortable: false
            }
            var opt = {
                dictLabel: dictLabel,	//必填
                dictValue: dictValue,	//必填
                tableId: "table",		//必填
                ruleId: listClass,		//必填
                align: "center",
                halign: "center",
                roleId: roleId,			//必填
                isMustFill: isMustFill,	//必填
                isDisabled: isDisabled,
                fillRoleIds: fillRoleIds,//必填
                formId: "formTable",		//必填
            };
            f = $.rule.fmRule(opt);

            if ("checkcyc" == dictValue) {//考核周期
                f = {
                    field: dictValue,
                    title: dictLabel,
                    sortable: false,
                    align: "center",
                    formatter: function (value, row, index) {
                        return value == null ? "-" : $.table.selectDictLabel([[${@dict.getType('zzjx_pefindicator_checkcyc')}]], value);
                    }
                }
            }
            if ("indPercents" == dictValue) {//权重
                f = {
                    field: dictValue,
                    title: dictLabel,
                    sortable: false,
                    visible: true,
                    align: "center",
                    formatter: function (value, row, index) {
                        return value == null || value == "" ? 0 + "%" : value + "%";
                    }
                }
            }
            columns.push(f);

            /* if (dictValue.slice(0,6) == "target" || dictValue.substr(-3,3) == "Get" ||dictValue.substr(-8,8) == "Complete" || dictValue == "comments") {
                f = updateRow(dictValue,dictLabel);
            }
            if (dictValue == "score"){
                f = {
                    field: "score",
                    title: dictLabel,
                    formatter: function (value, row , index) {
                        if (value == "" || typeof(value) == "undefined" ){
                            return '<input type="text"  oninput = "value=value.replace(/[^\\d]/g,\'\')"  class="inp" name="score" value="" onblur="changeData('+ index +', this);" />';
                        } else {
                            return '<input type="text" class="inp" name="score" value="'+value+'" onblur="changeData('+ index +', this);" />';
                        }
                    }
                }
            }
            columns.push(f); */
        }

        columns.push(
            {
                field: "scoringMethod",
                title: "公式ID",
                visible: false,
            }
        );


        $el.bootstrapTable('destroy').bootstrapTable({
            columns: columns,
            data: list,
            search: false,
            showSearch: false,
            showRefresh: false,
            showToggle: false,
            showColumns: false,
            showExport: false,                     //是否显示导出
            exportDataType: "basic",              //basic', 'all', 'selected'.
            height: 600,
            pagination: false,
            modalName: "考核指标",
            onPostBody: function (data) {
                bding();
            }
        });

        beforeAddRowLen = rows;

    }

    /**
     * 构建预览信息表格 --构建此表格只为导出数据
     *
     */
    function buildTable2($el, cells, rows, dictData, list) {
        var i, j, row, columns = [], data = [];
        columns.push({
            field: "id",
            title: "ID",
            visible: false
        })
        //拼接table,拼接表头
        for (var dd in dictData) {
            var dictLabel = dictData[dd]["dictLabel"];//显示名称
            var dictValue = dictData[dd]["dictValue"];//字段值
            var f = {
                field: dictValue,
                title: dictLabel,
                sortable: false
            }
            columns.push(f);
        }


        $el.bootstrapTable('destroy').bootstrapTable({
            columns: columns,
            data: list,
            search: false,
            showSearch: false,
            showRefresh: false,
            showToggle: false,
            showColumns: false,
            showExport: false,                     //是否显示导出
            exportDataType: "basic",              //basic', 'all', 'selected'.

            pagination: false,
            modalName: "考核指标"
        });


    }

    function updateRow(dictValue, dictLabel) {
        return {
            field: dictValue,
            title: dictLabel,
            formatter: function (value, row, index) {
                if (value == "" || typeof (value) == "undefined") {
                    return '<input type="text" class="inp" name="' + dictValue + '" value="" onblur="changeData(' + index + ', this);" />';
                } else {
                    return '<input type="text" class="inp" name="' + dictValue + '" value="' + value + '" onblur="changeData(' + index + ', this);" />';
                }
            }
        }
    }


    function changeData(index, obj) {
        var value = $(obj).val();
        var name = $(obj).attr('name');
        //通过 index 获取指定的行
        var row = $("#table").bootstrapTable('getOptions').data[index];
        //将 input 的值存进 row 中
        row[name] = value;
        //更新指定的行，调用 'updateRow' 则会将 row 数据更新到 data 中，然后再重新加载
        //$("#table").bootstrapTable('updateRow',{index: index, row: row});
    }

    function saveData(index, field, value) {
        $("#table").bootstrapTable('updateCell', {
            index: index,       //行索引
            field: field,       //列名
            value: value
        })
    }

    //得到表的数据
    function getDate() {
        alert(JSON.stringify($("#table").bootstrapTable('getData')));
    }

    function importExcel() {
        var currentId = 'importForm';
        layer.open({
            type: 1,
            area: ['400px', '230px'],
            fix: false,
            //不固定
            maxmin: true,
            shade: 0.3,
            title: '导入考核指标信息',
            content: $('#' + currentId),
            btn: ['<i class="fa fa-check"></i> 导入', '<i class="fa fa-remove"></i> 取消'],
            // 弹层外区域关闭
            shadeClose: true,
            btn1: function (index, layero) {
                var file = layero.find('#file').val();
                if (file == '' || (!$.common.endWith(file, '.xls') && !$.common.endWith(file, '.xlsx'))) {
                    $.modal.msgWarning("请选择后缀为 “xls”或“xlsx”的文件。");
                    return false;
                }
                var index = layer.load(2, {shade: false});
                $.modal.disable();
                var formData = new FormData();
                formData.append("file", $('#file')[0].files[0]);
                /* $.modal.loading('正在导入，请稍侯...'); */
                $.ajax({
                    url: ctx + "zzjx/pefctasstable/importData",
                    data: formData,
                    cache: false,
                    contentType: false,
                    processData: false,
                    type: 'POST',
                    success: function (result) {
                        if (result.code == web_status.SUCCESS) {
                            $.modal.closeAll();
                            //更新表格信息
                            updateGridData(result.excelData);

                            /* 								$("#table").bootstrapTable('toggleView');
                                                            $("#table").bootstrapTable('toggleView'); */
                            $.modal.alertSuccess(result.msg);

                        } else {
                            layer.close(index);
                            $.modal.enable();
                            $.modal.alertError(result.msg);
                        }
                    }
                });
            }
        });
    }

    function exportData() {
        var nodeListOf = document.querySelector("#table2");
        var sheet = XLSX.utils.table_to_sheet(nodeListOf);//将一个table对象转换成一个sheet对象
        //openDownloadDialog(sheet2blob(sheet),'指标信息.xlsx');

        var filename = "考核指标.xlsx"; //文件名称
        var ws_name = "Sheet1"; //Excel第一个sheet的名称
        var wb = XLSX.utils.book_new();
        XLSX.utils.book_append_sheet(wb, sheet, ws_name);  //将数据添加到工作薄
        XLSX.writeFile(wb, filename); //导出Excel

    }

    /**
     * 根据Excel数据更新表格信息
     */
    function updateGridData(excelData) {
        var rowList = new Array();
        var arr = getTableTh();
        for (var i = 0; i < excelData.length; i++) {
            //每一行的数据

            var row = $("#table").bootstrapTable('getOptions').data[i];
            var rowData = excelData[i];
            for (var j = 0; j < rowData.length; j++) {
                var field = arr[j]["field"];
                var thName = arr[j]["thName"];
                //只更新这几列的数据
                if (field.slice(0, 6) != "target" && field.substr(-3, 3) != "Get" && field != "score" && field != "comments" && field.substr(-8, 8) != "Complete") {
                    continue;
                }

                //将一行数据放到map里，统一修改
                //console.log(field+i+"行"+j+"列");
                if (rowData[j] != "" && rowData[j] != null && rowData[j] != "-") {
                    /*  saveData(i, field, rowData[j]); */
                    var value = rowData[j];
                    if (typeof (row[field]) == undefined) continue;
                    if (isNaN(value) && field == "score") {
                        row[field] = "";
                    } else {
                        row[field] = value;
                    }
                }
            }
            rowList[i] = row;
            /* $("#table").bootstrapTable('updateRow',{index: i, row: row}); */
        }
        $('#table').bootstrapTable('load', rowList);
    }


    /**
     * 获取表头数据
     */
    function getTableTh() {
        var arr = new Array();
        $("#table").find("tr").find("th").each(function () {
            var thArr = $(this);
            for (var i = 0; i < thArr.length; i++) {
                var map = {};
                map["field"] = thArr.data('field');
                map["thName"] = thArr.find("div")[0].innerText;
                arr.push(map);
            }
        });
        return arr;
    }

    //弹出层提示公告
    function alterTips() {
        var tips = $("#noticeTitle").val();
        var noticeValue = $("#noticeValue").text();
        debugger
        if (tips.length > 0) {
            layer.open({
                area: ['700px', '450px'],
                title: "公告标题：" + tips,
                content: noticeValue
            });
        }
    }

    function uploadFiles(type) {
        var objId = $("#objId").val();
        if (objId != "") {
            $.modal.loading("正在加载数据，请稍后...");
            var url = ctx + "zzjx/projectSysfile/toProjectSysfile?objId=" + objId + "&type=" + type;
            debugger
            var _url = $.common.isEmpty(url) ? "/404.html" : url;
            var _height = ($(window).height() - 250);
            layer.open({
                type: 2,
                maxmin: true,
                shade: 0.3,
                title: '附件上传',
                fix: false,
                area: [950 + 'px', _height + 'px'],
                content: _url,
                shadeClose: false,
                btn: ['<i class="fa fa-close"></i> 关闭'],
                cancel: function () {
                    return true;
                }
            });
            $.modal.closeLoading();
        }
    }

    function loadFiles(type) {
        var objId = $("#objId").val();
        var isUpload = $("#isUpload").val();
        if (type == "A") {
            isUpload = "N";
        }
        if (objId != "") {
            $.modal.loading("正在加载数据，请稍后...");
            var url = ctx + "zzjx/projectSysfile/toloadGrantfile?objId=" + objId + "&type=" + type + "&grant=" + isUpload;
            debugger
            var _url = $.common.isEmpty(url) ? "/404.html" : url;
            var _height = ($(window).height() - 270);
            layer.open({
                type: 2,
                maxmin: true,
                shade: 0.3,
                title: '查看附件',
                fix: false,
                area: [771 + 'px', _height + 'px'],
                content: _url,
                shadeClose: false,
                btn: ['<i class="fa fa-close"></i> 关闭'],
                cancel: function () {
                    return true;
                }
            });
            $.modal.closeLoading();
        }
    }

    function appealfun() {
        var approverId = $("#id").val();
        var roleId = $("#roleId").val();
        $.modal.loading("正在加载数据，请稍后...");
        var url = ctx + "zzjx/appealTab/toAppeal/" + approverId + "/" + roleId;
        debugger
        var _url = $.common.isEmpty(url) ? "/404.html" : url;
        var _height = ($(window).height() - 50);
        layer.open({
            type: 2,
            maxmin: true,
            shade: 0.3,
            title: '申诉管理',
            fix: false,
            area: [1199 + 'px', _height + 'px'],
            content: _url,
            shadeClose: false,
            btn: ['<i class="fa fa-close"></i> 关闭'],
            cancel: function () {
                return true;
            }
        });
        $.modal.closeLoading();
    }

    //我分解的列表
    function myApportion() {
        var approverId = $("#id").val();
        var roleId = $("#roleId").val();
        var url = ctx + "zzjx/pefctasstable/myApportion/" + approverId + "/" + roleId;
        $.modal.openFull("分解列表", url);


    }

    //我分解的列表
    function myApportionOrg() {
        var roleId = $("#roleId").val();
        var projectId = $("#projectId").val();
        var url = ctx + "zzjx/pefctasstable/myApportionOrg/" + projectId + "/" + roleId;
        $.modal.openFull("全部分解任务", url);


    }

    //分解
    function apportion() {

        var peftempletindicatorID = $("#peftempletindicatorID").val();

        var dept = $("#treeId").val();

        if (!dept) {
            $.modal.alert("请选择分解部门!");
            return;
        }
        var loginDept = $("#deptId").val();


        if (dept.indexOf(loginDept) >= 0) {
            alert(dept);
            alert(loginDept);
            alert(dept.indexOf(loginDept));
            $.modal.alert("不能分解给本部门,请从新选择要分解给的部门");
            return;
        }

        debugger
        var rows = $("#table").bootstrapTable('getData').length;
        var tableDataJson = null;
        var affterAddRowLen = rows;
        var rowList = new Array();

        if (affterAddRowLen > beforeAddRowLen) {
            for (var i = beforeAddRowLen; i < affterAddRowLen; i++) {
                //新增的每一行指标数据

                var row = $("#table").bootstrapTable('getOptions').data[i];
                //分解选中的自定义添加的指标
                if (row["0"] != null) {
                    rowList.push(row);
                }
            }

            tableDataJson = JSON.stringify(rowList);
        }

        var roleId = $("#roleId").val();
        var projectId = $("#projectId").val();
        var approveorder = $("#approveorder").val();
        var approveId = $("#id").val();
        $.ajax({
            url: ctx + "zzjx/pefctasstable/toApportion"
            ,
            data: {
                "deptIds": dept,
                "peftempletindicatorID": peftempletindicatorID,
                "projectId": projectId,
                "tableDataJson": tableDataJson,
                "roleId": roleId,
                "approveorder": approveorder,
                "approveId": approveId
            }
            ,
            dataType: "JSON"
            ,
            type: "GET"
            ,
            async: false
            ,
            success: function (result) {
                $.modal.alert(result.msg);
                doChange();
            },
            error: function () {
                $.modal.closeLoading();
                $.modal.alertError("分解失败!请联系管理员");
            }
        })


    }


    /*分解指标选择部门*/
    function selectDept() {

        var row = $.map($('#table').bootstrapTable('getSelections'), function (row) {
            return row;
        });
        var length = row.length;
        if (length < 1) {
            $.modal.alert("请选择要分解的数据!");
            return;
        }

        var id = new Array();
        for (var i = 0; i < row.length; i++) {
            id.push(row[i].pefindicatorId);

        }
        $("#peftempletindicatorID").val(id);

        var options = {
            title: '分解给选择部门',
            width: "700",
            url: ctx + "zzjx/deptparameterset/selDeptparameterset",
            callBack: doSubmit2
        };
        $.modal.openOptions(options);
    }

    function doSubmit2(index, layero) {
        var iframe = layero.find("iframe")[0].contentWindow;
        var row = $.map(iframe.$('#bootstrap-table').bootstrapTable('getSelections'), function (row) {
            return row;
        });
        var deptCodeArr = new Array();
        var deptNameArr = new Array();
        if (row.length > 0) {
            for (var i = 0; i < row.length; i++) {
                var deptCode = row[i].deptCode;
                var deptName = row[i].deptName;
                deptCodeArr.push(deptCode);
                deptNameArr.push(deptName);
            }

        }
        $("#treeId").val(deptCodeArr);
        $("#treeName").val(deptNameArr);
        layer.close(index);
        apportion();

    }


    /* 新增表格行 */
    function insertRow() {
        var arr = getRows();
        var len = $('#table').bootstrapTable('getData').length;
        $("#table").bootstrapTable('insertRow', {
            index: len + 1, // 你想插入到哪，0表示第一行
            row: arr
        })
        console.log(len);
    }

    /*获取列头字段*/
    function getRows() {
        var rows = {};
        var roleId = $("#roleId").val();
        var table = "table";
        var index = $('#table').bootstrapTable('getData').length;
        rows["id"] = guid();
        rows["pefindicatorId"] = guid();
        for (var dd in data) {
            var dictLabel = data[dd]["dictLabel"];//显示名称
            var dictValue = data[dd]["dictValue"];//字段值
            var listClass = dictData[dd]["listClass"];//列显示类型(输入框，下拉框，显示)
            if (listClass == "" || listClass == null) {
                rows[dictValue] = '<input type="text" style="border:solid 1px #63CFF2;width:70px;" class=" " name="' + dictValue + '" value="" onblur="$.rule.changeData2(' + index + ', this,' + table + ')" placeholder="">';
            } else {
                rows[dictValue] = "";
            }
            /*rows.push(f);*/

        }
        return rows;
    }

    function guid() {
        function S4() {
            return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
        }

        return (S4() + S4() + "-" + S4() + "-" + S4() + "-" + S4() + "-" + S4() + S4() + S4());
    }

    function loadMsg() {

        var tableData = $("#table").bootstrapTable('getData');
        console.log(tableData);
        if (tableData.length > 0 && tableData instanceof Array) {
            $('#table tr').each(function (i) {                   // 遍历 tr
                $(this).children('td').each(function (j) {  // 遍历 tr 的各个 td
                    var datai = $(this).find("input[type='text']").val();

                    if (datai == "null") {
                        $(this).find("input[type='text']").val("");

                    }
                });
            });

        }

    }
</script>
</body>
<form class="mt20 mb10" enctype="multipart/form-data" id="importForm" style="display: none;">
    <div class="col-xs-offset-1">
        <input id="file" name="file" type="file"/>
        <font class="pull-left mt10" color="red">
            提示：仅允许导入“xls”或“xlsx”格式文件！
        </font>
    </div>
</form>
</html>
